home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Comm / tcp / JabberwockySRC.lha / Jabberwocky / src / write.c < prev    next >
Encoding:
C/C++ Source or Header  |  2003-03-29  |  5.5 KB  |  189 lines

  1. /*  Copyright (C) 2002 Tom Parker (tom@carrott.org),
  2.                        Matthias Münch (matthias@amigaworld.de)
  3.  
  4.     This program is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation; either version 2 of the License, or
  7.     (at your option) any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17.  
  18.     In addition, as a special exception, Tom Parker and Matthias Münch give
  19.     permission to link the code of this program with a TCP stack of your 
  20.     choice, any official MUI libraries or classes and any custom MUI classes
  21.     that should be necessary for the operation of this program.  This 
  22.     exception also gives you permission to distribute linked combinations 
  23.     including this software with any of the before-mentioned libraries and 
  24.     classes.  You must obey the GNU General Public License in all respects for
  25.     all of the code used other than that provided by the before-mentioned 
  26.     libraries and classes.  As part of this exception you are obliged to 
  27.     follow the license terms of the before-mentioned libraries, this license
  28.     does not compel you to follow those terms, but if you do not then you may
  29.     not link with those libraries.  If you modify this file, you may extend
  30.     this exception to your version of the file, but you are not obligated to
  31.     do so.  If you do not wish to do so, delete this exception statement from
  32.     your version.
  33. */
  34. /*
  35. ** message compose window
  36. */
  37.  
  38. #include "common.h"
  39.  
  40. #include <MUI/TextEditor_mcc.h>
  41.  
  42. ULONG write_new(struct IClass *cl, Object *obj, struct opSet *msg);
  43. void write_send(Object *obj, struct writedata *data);
  44.  
  45.  
  46. MUI_DISPATCH(write_dispatch)
  47. {
  48.     switch(msg->MethodID)
  49.     {
  50.         case OM_NEW:
  51.             return write_new(cl,obj,(APTR)msg);
  52.  
  53.         case WRITE_SEND:
  54.             write_send(obj, INST_DATA(cl,obj));
  55.             return(0);
  56.  
  57.  
  58.     }
  59.     return(DoSuperMethodA(cl,obj,msg));
  60. }
  61.  
  62.  
  63. ULONG write_new(struct IClass *cl, Object *obj, struct opSet *msg)
  64. {
  65.     struct writedata *data;
  66.     Object *tostr, *substr, *texted, *slider, *sendbut, *canbut;
  67.     char *user, *thread, *body;
  68.  
  69.     obj = (Object *)DoSuperNew(cl,obj,
  70.         MUIA_Window_Title, MSG_WRITE_MESSAGE_TITLE,
  71.         MUIA_HelpNode, "window-writemsg",
  72.         WindowContents, VGroup,
  73.             Child, ColGroup(2),
  74.                 Child, Label2(MSG_WRITE_TO),
  75.                 Child, (ULONG) tostr = StringObject,
  76.                     StringFrame,
  77.                     MUIA_String_AdvanceOnCR, TRUE,
  78.                     MUIA_CycleChain, 1,
  79.                 End,
  80.                 Child, Label2(MSG_WRITE_THREAD),
  81.                 Child, (ULONG) substr = StringObject,
  82.                     StringFrame,
  83.                     MUIA_String_AdvanceOnCR, TRUE,
  84.                     MUIA_CycleChain, 1,
  85.                 End,
  86.             End,
  87.             Child, HGroup,
  88.                 Child, (ULONG) texted = TextEditorObject,
  89.                     MUIA_CycleChain, 1,
  90.                 End,
  91.                 Child, (ULONG) slider = ScrollbarObject,
  92.                 End,
  93.             End,
  94.             Child, HGroup,
  95.                 Child, (ULONG) sendbut = SimpleButton(MSG_WRITE_SEND_GAD),
  96.                 Child, (ULONG) canbut = SimpleButton(MSG_WRITE_CANCEL_GAD),
  97.             End,
  98.         End,
  99.         TAG_MORE, msg->ops_AttrList);
  100.  
  101.     if(!obj) return(0);
  102.  
  103.     set(texted, MUIA_TextEditor_Slider, (ULONG) slider);
  104.  
  105.     user = (char *)GetTagData(WRITE_TO, NULL, msg->ops_AttrList);
  106.     thread = (char *)GetTagData(WRITE_THREAD, NULL, msg->ops_AttrList);
  107.     body = (char *)GetTagData(WRITE_QUOTE, NULL, msg->ops_AttrList);
  108.     
  109.     user = iks_strdup(convert_locale(user));
  110.     body = iks_strdup(convert_locale(body));
  111.     thread = iks_strdup(convert_locale(thread));
  112.     
  113.     if (user) {
  114.         set(tostr, MUIA_String_Contents, (ULONG) user);
  115.     }
  116.     if (thread) {
  117.         set(substr, MUIA_String_Contents, (ULONG) thread);
  118.     }
  119.     if (body) {
  120.         set(texted, MUIA_TextEditor_Contents, (ULONG) body);
  121.     }
  122.     
  123.     data = INST_DATA(cl,obj);
  124.     data->tostr = tostr;
  125.     data->substr = substr;
  126.     data->texted = texted;
  127.  
  128.  
  129.     DoMethod(sendbut, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, WRITE_SEND);
  130.  
  131.     DoMethod(canbut, MUIM_Notify, MUIA_Pressed, FALSE, MUIV_Notify_Application, 5, MUIM_Application_PushMethod, gui.list, 2, ROSTER_CLOSEME, obj);
  132.     DoMethod(obj, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, MUIV_Notify_Application, 5, MUIM_Application_PushMethod, gui.list, 2, ROSTER_CLOSEME, obj);
  133.  
  134.     free(user);
  135.     free(body);
  136.     free(thread);
  137.     
  138.     return((ULONG)obj);
  139. }
  140.  
  141.  
  142. void write_send(Object *obj, struct writedata *data)
  143. {
  144.     char *to, *sub, *text;
  145.     iks *x;
  146.  
  147.     if(net.state != NET_ON)
  148.     {
  149.         printf("not connected yet!\n");
  150.         DoMethod(gui.app, MUIM_Application_PushMethod, gui.list, 2, ROSTER_CLOSEME, obj);
  151.         return;
  152.     }
  153.  
  154.     to = mui_sget(data->tostr);
  155.     sub = mui_sget(data->substr);
  156.     text = (char *)DoMethod(data->texted, MUIM_TextEditor_ExportText);
  157.  
  158.     if(to)
  159.     {
  160.         to = strdup(convert_utf8(to));
  161.         if (sub) {
  162.             sub = strdup(convert_utf8(sub));
  163.         }
  164.         x = iks_make_msg(IKS_TYPE_NONE, to, convert_utf8(text), sub);
  165.         iks_send(net.parser, x);
  166.         iks_delete(x);
  167.         free(to);
  168.         if (sub) {
  169.             free(sub);
  170.         }
  171.     }
  172.  
  173.  
  174.     FreeVec(text);
  175.     DoMethod(gui.app, MUIM_Application_PushMethod, gui.list, 2, ROSTER_CLOSEME, obj);
  176. }
  177.  
  178.  
  179. void write_to(char *to, char *thread, char *body)
  180. {
  181.     Object *win;
  182.  
  183.     win = NewObject(gui.write_mcc->mcc_Class, NULL, WRITE_TO, (ULONG) to, WRITE_THREAD, (ULONG) thread, WRITE_QUOTE, (ULONG) body, TAG_DONE);
  184.     if(win) {
  185.         DoMethod(gui.app, OM_ADDMEMBER, win);
  186.         set(win, MUIA_Window_Open, TRUE);
  187.     }
  188. }
  189.